<template>
  <div>
    <el-dialog
      title="协同批注"
      :visible.sync="dialogVisible"
      width="1000px"
      @closed="resetForm('form')"
      :lock-scroll="false"
      :close-on-click-modal="false"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="80px">
        <el-form-item label="策略建议" prop="content">
          <UEditor ref="ueditor" :ueHeight="320" :defaultMsg="form.content" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="custom" v-preventReClick @click="submitForm('form')">
          提 交
        </el-button>
        <el-button @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { sysKnowledgeStrategyAdd } from "@/api/admin/courseLibrary/sysKnowledgeStrategy.js";
import Bus from "@/utils/bus.js";
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        resId: "",
        content: "",
        auditStatus: "1",
        resType: "1", //资源类型；1-知识点，2-其他，3-…
      },
      rules: {
        content: [
          { required: true, message: "请输入策略建议", trigger: "blur" },
        ],
      },
    };
  },
  mounted() {
    Bus.$on("showDialogStrategy", (v) => {
      this.form.content = v.strategy;
      this.form.resId = v.id;
      this.dialogVisible = true;
    });
  },
  beforeDestroy() {
    Bus.$off("showDialogStrategy");
  },
  methods: {
    submitForm(form) {
      this.form.content = this.$refs.ueditor.message;
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.add();
        }
      });
    },
    add() {
      sysKnowledgeStrategyAdd(this.form).then((res) => {
        this.dialogVisible = false;
        this.$message({
          message: "策略建议已提交，请等待批复",
          type: "success",
        });
      });
    },
    //重置表单
    resetForm(form) {
      this.$refs[form].resetFields();
      this.form.resId = "";
      this.form.content = "";
    },
  },
};
</script>